from ultralytics.data import YOLODataset
from ultralytics.cfg import cfg2dict
from ultralytics.data.augment import Format
import cv2

# 测试数据获取
config = cfg2dict('./coco8/coco8.yaml')
dataset = YOLODataset(data=config, img_path='./coco8/images')
labels = dataset.get_image_and_label(1)
# 打印数据
#print(labels)

# 格式化数据后打印结果
format = Format(normalize=False)
format_labels = format(labels)
img = format_labels['img'].permute(1,2,0).numpy()
savedir = './format_test.jpg'
cv2.imwrite(savedir, img)
print(format_labels)